import {
  PostPageParams,
  PostPageListGetResultModel,
  PostListItem,
  UploadRoleResult,
} from './model/systemModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';

enum Api {
  PostPageList = '/admin/post/page',
  InfoPost = '/admin/post',
  ADDPost = '/admin/post/add',
  DelPost = '/admin/post/del',
  UpdatePost = '/admin/post/update',
  ExportPost = '/admin/post/export',
  TempPost = '/admin/sys-file/local/file/post.xlsx',
  ImportPost = '/admin/post/import',
}
export const getPostListByPage = (params?: PostPageParams) =>
  defHttp.get<PostPageListGetResultModel>({ url: Api.PostPageList, params });

export const addPostApi = (params: PostListItem) => defHttp.post<any>({ url: Api.ADDPost, params });

export const updatePostApi = (params: PostListItem) =>
  defHttp.post<any>({ url: Api.UpdatePost, params });

export const deletePostApi = (id: string) => defHttp.post<any>({ url: Api.DelPost + '/' + id });
export const getPostInfoApi = (id: string) => defHttp.get<any>({ url: Api.InfoPost + '/' + id });

export const exportPostApi = () =>
  defHttp.get<any>(
    { url: Api.ExportPost, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export const tempPostApi = () =>
  defHttp.get<any>(
    { url: Api.TempPost, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export function uploadPostApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadRoleResult[]>(
    {
      url: Api.ImportPost,
      onUploadProgress,
    },
    params,
  );
}
